<?php
	
	// Add RSS links to <head> section
	automatic_feed_links();
	
	// Load jQuery
	if ( !is_admin() ) {	   
	   wp_enqueue_script('jquery');
	}
	
	// Clean up the <head>
	function removeHeadLinks() {
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    }
    add_action('init', 'removeHeadLinks');
    remove_action('wp_head', 'wp_generator');
    
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Sidebar Widgets',
    		'id'   => 'sidebar-widgets',
    		'description'   => 'These are widgets for the sidebar.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h4>',
    		'after_title'   => '</h4>'
    	));
    }

    register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
    register_nav_menu( 'footer_menu', __( 'Footer Menu', 'twentytwelve' ) );

    add_filter('body_class', 'ctw2_filter_body_class');

    function ctw2_filter_body_class($classes) {
            $classes[] = 'fixed-header';
            return $classes;
    }

    /*SHORT CODE*/

    function ctw2_sc_statement( $atts ) {
         $content = $atts['noi_dung'];
         $html = '<div class="well well-lg" style="margin-bottom: 90px;">' .
                '<p class="soliloquy-home-well no-margin text-center" style="font-style:italic;font-size:28px;">' . $content . '</p>' .
             '</div>';
         return $html;
    }
    add_shortcode('PHAT_BIEU', 'ctw2_sc_statement');

    function ctw2_sc_headline( $atts ) {
         $content = $atts['noi_dung'];
         $html =  '<h2 class="text-center">'. $content .'</h2>';
         return $html;
    }
    add_shortcode('HEAD_LINE', 'ctw2_sc_headline');

     function ctw2_sc_video( $atts ) {
         $url = $atts['hinh_dai_dien'];
         $title = $atts['tieu_de'];
         $youtube_id = $atts['youtube_id'];
         $html =  '<a href="#" class="soliloquy-video" data-video-id="' . $youtube_id .'" title="'. $title . '"><img src="' . $url .'" alt="'. $title .'">' .
         '<span class="video-icon">' .
         '</span></a>';
         return $html;
    }
    add_shortcode('VIDEO', 'ctw2_sc_video');

    function ctw2_sc_seperator( $atts ) {
         $html = '<div class="container"><div class="div-sep"></div> </div>';
         return $html;
    }
    add_shortcode('DUONG_KE_NGANG', 'ctw2_sc_seperator');

    function ctw2_sc_testimonials( $atts ) {
         $content = $atts['noi_dung'];
         $customer_name = $atts['ten_khach_hang'];
         $url = $atts['url'];
         $url_title = $atts['tieu_de_url'];
         $position = $atts['vi_tri'];
         if($position === 'trai'){
            $class = 'clearfix';
         }else{
            $class = 'pull-right';
         }
         $html =  '<blockquote class="'.$class.'">' .
                    '<a class="customer-photo" href="'. $url .'"> <img src="http://www.bizweb.vn/Upload/Counselors/20121113161345905.JPG" alt="" title=""/></a>' .
                     $content .
                    '<cite>'.$customer_name. ', ' . '<a href="'.$url.'" target="blank" style="text-transform:none;letter-spacing:0">'.$url_title.'</a></cite>' .
                 '</blockquote>';
         return $html;
    }
    add_shortcode('LOI_KHEN_CUA_KHACH_HANG', 'ctw2_sc_testimonials');

    function ctw2_sc_call_to_action( $atts ) {
         $content = $atts['noi_dung'];
         $url = $atts['url'];
         $title_button = $atts['tieu_de_nut_nhan'];

         $html =    '<div class="home-supports clearfix">'.
                        '<div class="home-supports-wrap container">'.
                           '<div class="home-supports-content row">'.
                              '<div class="col-lg-12">'.
                                 '<h2 class="text-center">'.$content.'</h2>'.
                              '</div>'.
                              '<div class="col-lg-12">'.
                              '   <p class="no-margin text-center"><a class="button" href="'.$url.'" title="Click here to get started with soliloquy.">'.$title_button.'</a></p>'.
                              '</div>'.
                           '</div>'.
                        '</div>'.
                    ' </div>';
         return $html;
    }
    add_shortcode('CALL_TO_ACTION', 'ctw2_sc_call_to_action');

    function ctw2_sc_chat_support_nick( $atts ) {
         $skype = $atts['skype'];
         $yahoo = $atts['yahoo'];
         $ten = $atts['ten'];
         $hinh_anh = $atts['hinh_anh'];
         $span = $atts['span'] ? $atts['span'] : 4;
         $skype_number = rand();
         $html =    '<div class="col-lg-'.$span.' supporter">'  .                  
                        '<img  src="'.$hinh_anh.'" class="attachment-full wp-post-image" alt="dynamic">'.
                        '<div class="name">'.$ten.'</div>'.
                        '<div class="chat-action">'.
                            '<div class="icon skype" id="SkypeButton_Call_'.$skype . '_' .$skype_number.'"></div>'.
                            '<a class="icon yahoo"href="ymsgr:sendim?'.$yahoo.'" mce_href="ymsgr:sendim?'.$yahoo.'"><img border=0 src="http://opi.yahoo.com/online?u='.$yahoo.'&m=g&t=1&l=us"></a>'.
                        '</div>'.
                    '</div>';

         $html.=  '<script type="text/javascript">'.
                    'jQuery(document).ready(function(){Skype.ui({'.
                      '"name": "chat",'.
                      '"element": "SkypeButton_Call_'.$skype . '_'.$skype_number.'",'.
                      '"participants": ["'.$skype.'"],'.
                      '"imageSize": 16'.
                    '});});'.
                  '</script>';
            
         return $html;
    }
    add_shortcode('NICK_CHAT', 'ctw2_sc_chat_support_nick');

    function ctw2_sc_grid_image( $atts ) {
         $tieu_de = $atts['tieu_de'];
         $mo_ta = $atts['mo_ta'];
         $noi_dung = $atts['noi_dung'];

        $html = '<div class="col-lg-12">'.
                 '<h2 class="text-center">Slider Addons</h2>'.
              '</div>'.
              '<div class="col-lg-12">'.
                 '<p class="text-center">Soliloquy doesnthe best responsive WordPress slider plugin without reason or cause. <strong>With 10+ powerful and useful addons, Soliloquy can be extended to do just about anything you can imagine.</strong></p>'.
              '</div>';

        $list = explode("|", $noi_dung);
        foreach ($list as &$value) {
            $item = explode(",", $value);
            $url = $item[0];
            $image = $item[1];
            $title = $item[2];

            $html.= '<div class="col-lg-4 home-addon">'.
                     '<a href="'.$url.'" title="'.$title.'"><img width="750" height="300" src="'.$image.'" class="attachment-full wp-post-image" alt="dynamic"></a>'.
                  '</div>';
        }

         return $html;
    }
    add_shortcode('GRID_IMAGE', 'ctw2_sc_grid_image');

     function ctw2_sc_featured( $atts ) {
         $url = $atts['url'];
         $url_title = $atts['tieu_de_url'];
         $photo_url = $atts['url_hinh'];
         $photo_title = $atts['tieu_de_hinh'];
         $title = $atts['tieu_de'];
         $description = $atts['mo_ta'];
         $position =  $atts['vi_tri_hinh'];
         $html =  '<div class="home-supports clearfix">' .
                    '<div class="home-supports-wrap container">'.
                       '<div class="home-supports-content row">'.
                           '<div class="col-lg-12">'.
                             '<h2>'. $title .'</h2>'.
                           '</div>';
        if($position === 'phai'){
           $html .=  
                  '<div class="col-lg-8">'.
                     '<p>'.$description.'</p>'.
                     '<p class="no-margin"><a class="button" href="'.$url.'" title="'.$url_title.'">'. $url_title .'</a></p>'.
                  '</div>'.
                   '<div class="col-lg-4">'.
                     '<img class="img-responsive soliloquy-site-preload" data-src="'.$photo_url.'" alt="'.$photo_title.'" src="'.$photo_url.'" style="opacity: 1;">'.
                  '</div>';
        }else{
            $html .=  
                    '<div class="col-lg-4">'.
                     '<img class="img-responsive soliloquy-site-preload" data-src="'.$photo_url.'" alt="'.$photo_title.'" src="'.$photo_url.'" style="opacity: 1;">'.
                    '</div>' .
                    '<div class="col-lg-8">'.
                     $description.
                     '<p class="no-margin"><a class="button" href="'.$url.'" title="'.$url_title.'">'. $url_title .'</a></p>'.
                    '</div>';
        }
                        
                         
        $html.=       '</div>'.
                    '</div>'.
                 '</div>';
         return $html;
    }
    add_shortcode('TINH_NANG', 'ctw2_sc_featured');


    function ctw2_numeric_posts_nav() {

        if( is_singular() )
            return;

        global $wp_query;

        /** Stop execution if there's only 1 page */
        if( $wp_query->max_num_pages <= 1 )
            return;

        $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
        $max   = intval( $wp_query->max_num_pages );

        /** Add current page to the array */
        if ( $paged >= 1 )
            $links[] = $paged;

        /** Add the pages around the current page to the array */
        if ( $paged >= 3 ) {
            $links[] = $paged - 1;
            $links[] = $paged - 2;
        }

        if ( ( $paged + 2 ) <= $max ) {
            $links[] = $paged + 2;
            $links[] = $paged + 1;
        }

        echo '<div class="pagination"><ul>' . "\n";

        /** Previous Post Link */
        if ( get_previous_posts_link() )
            printf( '<li>%s</li>' . "\n", get_previous_posts_link() );

        /** Link to first page, plus ellipses if necessary */
        if ( ! in_array( 1, $links ) ) {
            $class = 1 == $paged ? ' class="active"' : '';

            printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

            if ( ! in_array( 2, $links ) )
                echo '<li>…</li>';
        }

        /** Link to current page, plus 2 pages in either direction if necessary */
        sort( $links );
        foreach ( (array) $links as $link ) {
            $class = $paged == $link ? ' class="active"' : '';
            printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
        }

        /** Link to last page, plus ellipses if necessary */
        if ( ! in_array( $max, $links ) ) {
            if ( ! in_array( $max - 1, $links ) )
                echo '<li>…</li>' . "\n";

            $class = $paged == $max ? ' class="active"' : '';
            printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
        }

        /** Next Post Link */
        if ( get_next_posts_link() )
            printf( '<li>%s</li>' . "\n", get_next_posts_link() );

        echo '</ul></div>' . "\n";

    }

    /*add_action('wp_head', 'show_template');
    function show_template() {
        global $template;
        echo basename($template);
    }*/

?>


 